** READ RESULTS FROM SIMULATION OF MENU COST MODEL AND PLOTS FIGB1 TABL B1

insheet using EDP_MultiK_CV.txt, clear tab

rename v1 irp
rename v2 ia
local i=c(k)
drop v$_i

tokenize "06 10 14"


local v = 3
* n prds in year
foreach f in 2 4 6 12{
	* annual inflation rates
	foreach p in 10 15 20 25 30 35 40 45 50{	
		* menu cost
		forvalues k=1/3{
			rename v$_v edp_p`p'_f`f'_k`$_k'
			replace edp_p`p'_f`f'_k`$_k' = edp_p`p'_f`f'_k`$_k' - 1
			local v = $_v + 1
			}
	}
}


reshape long edp_p10_ edp_p15_ edp_p20_ edp_p25_ edp_p30_ edp_p35_ edp_p40_ edp_p45_ edp_p50_, i(irp ia) j(pik, string)
split pik, parse(_)
drop pik
rename pik1 nprd
rename pik2 k

save SimData_MultiKMultiPrdConstCV, replace


insheet using StatDistr_MultiK_CV.txt, clear tab

rename v1 irp
rename v2 ia
local i=c(k)
drop v$_i

tokenize "06 10 14"

local v = 3
* n prds in year
foreach f in 2 4 6 12{
	* annual inflation rates
	foreach p in 10 15 20 25 30 35 40 45 50{	
		* menu cost
		forvalues k=1/3{
			rename v$_v stdistr_p`p'_f`f'_k`$_k'
			local v = $_v + 1
			}
	}
}

reshape long stdistr_p10_ stdistr_p15_ stdistr_p20_ stdistr_p25_ stdistr_p30_ stdistr_p35_ stdistr_p40_ stdistr_p45_ stdistr_p50_, i(irp ia) j(pik, string)
split pik, parse(_)
drop pik
rename pik1 nprd
rename pik2 k

merge 1:1 irp ia k nprd using SimData_MultiKMultiPrdConstCV
tab _m
save SimData_MultiKMultiPrdConstCV, replace


use SimData_MultiKMultiPrdConstCV, clear

*keep if k=="k06"|k=="k10"|k=="k14"
keep if k=="k10"

egen T=rowtotal(stdistr_*)
egen minw=rowmin(stdistr*)

keep if minw!=0
keep irp ia k nprd edp* T

* COMPUTE DERIVATIVE OF EDP (with 0.5pp increments in Epi)

forvalues z = 15(5)50{
	local i = $_z - 5
	gen D_edp_10_`z' = (edp_p`z'_ - edp_p10_)/( ($_z - 10)/1000 )
	
	gen DD_edp_`i'_`z' = (edp_p`z'_ - edp_p`i'_)/0.005
	
}

preserve
keep irp ia nprd DD* T
reshape long DD_edp_, i(irp ia nprd) j(deltapi, string)
collapse (min) minDD=DD_ (max) maxDD=DD_ (p10) p10DD=DD_ (p20) p20DD=DD_ (p50) p50DD=DD_ (p80) p80DD=DD_ (p90) p90DD=DD_ (mean) meanDD=DD_ [aw=T], by(deltapi nprd)

local nn=_N
set obs `=_N+4'
     replace nprd="f12" if _n==`=$_nn+1' & nprd==""
     replace nprd="f2" if _n==`=$_nn+2' & nprd==""
     replace nprd="f4" if _n==`=$_nn+3' & nprd==""
     replace nprd="f6" if _n==`=$_nn+4' & nprd==""

gen n_ndec=real(substr(nprd,2,1))
replace n_ndec=12 if nprd=="f12"
labmask n_ndec, val(nprd)

gen n_infl = real(substr(deltapi,1,2))
gen s_infl =      substr(deltapi,1,2)

sort n_ndec n_infl 
gen t=_n

lab def lt 1 "1.0" 2 "1.5" 3 "2.0" 4 "2.5" 5 "3.0" 6 "3.5" 7 "4.0" 8 "4.5" 9 " " 10 "1.0" 11 "1.5" 12 "2.0" 13 "2.5" 14 "3.0" 15 "3.5" 16 "4.0" 17 "4.5" 18 " " 19 "1.0" 20 "1.5" 21 "2.0" 22 "2.5" 23 "3.0" 24 "3.5" 25 "4.0" 26 "4.5" 27 " " 28 "1.0" 29 "1.5" 30 "2.0" 31 "2.5" 32 "3.0" 33 "3.5" 34 "4.0" 35 "4.5"

lab val t lt
format min max p10 p50 p90 mean %3.1f
twoway rbar min max t, barw(0.1) col(black*0.5) || rbar p10 p50  t, barw(0.8) fcol(ltbluishgray) lc(black) ||rbar p50 p90 t, barw(0.8) fcol(ltbluishgray) lc(black) /*||scatter mean t , msy(d) msi(*0.5) mco(red)*/ xla(1(1)35, valuelab angle(90) labsi(*0.8) notick) legend(off) yla(0(0.5)2, labsi(*0.8) angle(0)) yscale(range(0 2.0)) text(1.7 4.5 "Semester") text(1.7 13.5 "Quarter") text(1.7 22.5 "2 months") text(1.7 31.5 "Month") /*xli(9 18 27)*/ graphregion(c(white)) xti("Expected annual inflation") xsize(20) ysize(12) text(1.9 18 "Price revisions every:") yti("Treatment effect ({&beta}{sup:n}{sub:s})")
graph export FigBetaKeq1OverPi_B1.eps, replace

restore

preserve
egen rmin=rowmin(DD*)
egen rmax=rowmax(DD*)
egen rave=rowmean(DD*)
egen rstd=rowsd(DD*)
gen rcva=rstd/rave


gen n_ndec=real(substr(nprd,2,1))
replace n_ndec=12 if nprd=="f12"
labmask n_ndec, val(nprd)
table n_ndec [aw=T], stat(min rcva) stat( p10 rcva) stat( p50 rcva ) stat(p90 rcva) stat( max rcva) nformat(%6.3f) nototal

restore
